package com.foodie.service;

import com.foodie.dao.DB;
import com.foodie.entity.User;
import com.foodie.entity.Menu;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class UserimgService {
    public List<Menu> getListimg() {

        List<Map<String, Object>> result = DB.executeQuery("SELECT * from t_menu");

        List<Menu> userList = new ArrayList<>();

        System.out.println(result);
        if (result != null) {
            for (int i = 0; i < result.size(); i++) {
                Map<String, Object> data = result.get(i);
                Menu image = new Menu();

                image.setID((Integer) data.get("ID"));
                image.setMENU_NAME((String) data.get("MENU_NAME"));
                image.setMENU_INTRODUCE((String) data.get("MENU_INTRODUCE"));
                image.setIMAGE((String) data.get("IMAGE"));
                image.setMENU_TIME((String) data.get("MENU_TIME"));
                image.setVIEW((Integer) data.get("VIEW"));

                image.setPRICE((Integer) data.get("PRICE"));
                image.setCREATE_TIME((String) data.get("CREATE_TIME"));
                image.setUPDATE_TIME((String) data.get("UPDATE_TIME"));

                userList.add(image);
            }
        }

        return userList;
    }
    public List<User> getUser(){
        List<Map<String,Object>> u = DB.executeQuery("select * from t_user");
        List<User> ulist = new ArrayList<>();
        if (u != null){
            for (int i =0; i< u.size(); i++){
                Map<String,Object> res = u.get(i);
                User user = new User();
                user.setId((Integer) res.get("ID"));
                user.setName((String) res.get("NAME"));
                user.setSex((String) res.get("SEX"));
                user.setPhone((String) res.get("PHONE"));
                user.setUser_id((String) res.get("USER_ID"));
                user.setUser_pwd((String) res.get("USER_PWD"));
                ulist.add(user);
            }
        }
        return ulist;
    }
}
